Crate buf_redux [] [src]

A drop-in replacement for std::io::BufReader with more functionality.

Method names/signatures and implemented traits are unchanged from std::io::BufReader, making replacement as simple as swapping the import of the type:

- use std::io::BufReader;
+ extern crate buf_redux;
+ use buf_redux::BufReader;

More Direct Control

Provides methods to:

  • Access the buffer through an &-reference without performing I/O
  • Force unconditional reads into the buffer
  • Shuffle bytes down to the beginning of the buffer to make room for more reading
  • Increase the capacity of the buffer
  • Get the number of available bytes as well as the total capacity of the buffer
  • Consume the BufReader without losing data
  • Get inner reader and trimmed buffer with the remaining data
  • Get a Read adapter which empties the buffer and then pulls from the inner reader directly *

More Sensible and Customizable Buffering Behavior

  • Tune the behavior of the buffer to your specific use-case using the types in the strategy module:
    • BufReader performs reads as dictated by the ReadStrategy trait.
    • BufReader shuffles bytes down to the beginning of the buffer, to make more room at the end, when deemed appropriate by the MoveStrategy trait.
  • BufReader uses exact allocation instead of leaving it up to Vec, which allocates sizes in powers of two.
    • Vec's behavior is more efficient for frequent growth, but much too greedy for infrequent growth and custom capacities.

See the BufReader type in this crate for more info.

Modules

strategy

Types which can be used to tune the behavior of BufReader.

Structs

BufReader

The pièce de résistance: a drop-in replacement for std::io::BufReader with more functionality.

Buffer

A deque-like datastructure for managing bytes.

Unbuffer

A Read adapter for a consumed BufReader which will empty bytes from the buffer before reading from inner directly. Frees the buffer when it has been emptied.

Traits

TrustRead

A trait which Buffer can use to determine whether or not it is safe to elide zeroing of its buffer.

Functions

copy_buf

Copy data between a BufRead and a Write without an intermediate buffer.

Type Definitions

DefaultMoveStrategy

The default MoveStrategy for this crate.

DefaultReadStrategy

The default ReadStrategy for this crate.